//
//  YBMySettingViewController.m
//  ZhongWangYuanApp
//
//  Created by apple on 2019/1/29.
//  Copyright © 2019年 apple. All rights reserved.
//

#import "YBMySettingViewController.h"
#import "MyInforChangeNameViewController.h"
#import "YBChangePhoneViewController.h"
#import "YBMySettingTableViewCell.h"
#define CELLID @"YBMySettingTableViewCell"

@interface YBMySettingViewController ()<UITableViewDelegate , UITableViewDataSource>
@property (nonatomic , strong) UITableView * tableView;

@property (nonatomic , strong) NSArray * titleArray;

@property (nonatomic , strong) NSArray * dataArray;

@end

@implementation YBMySettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titlelabel.text = @"个人资料";
    self.titleArray = @[@"头像" , @"姓名" , @"单位" , @"登录名" , @"手机号"];
    
    self.dataArray = @[
                       [NSString string:YBUSERINFOMODEL.photopath isNilStringReturnDeftString:@"暂无"] ,
                       [NSString string:YBUSERINFOMODEL.name isNilStringReturnDeftString:@"暂无"] ,
                       [NSString string:YBUSERINFOMODEL.company isNilStringReturnDeftString:@"暂无"] ,
                       [NSString string:YBUSERINFOMODEL.logname isNilStringReturnDeftString:@"暂无"] ,
                       [NSString string:YBUSERINFOMODEL.cellphone isNilStringReturnDeftString:@"暂无"]
                       ];
    
    [self initUserInterface];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.dataArray = @[
                       [NSString string:YBUSERINFOMODEL.photopath isNilStringReturnDeftString:@"暂无"] ,
                       [NSString string:YBUSERINFOMODEL.name isNilStringReturnDeftString:@"暂无"] ,
                       [NSString string:YBUSERINFOMODEL.company isNilStringReturnDeftString:@"暂无"] ,
                       [NSString string:YBUSERINFOMODEL.logname isNilStringReturnDeftString:@"暂无"] ,
                       [NSString string:YBUSERINFOMODEL.cellphone isNilStringReturnDeftString:@"暂无"]
                       ];
    [self.tableView reloadData];
}


-(void)initUserInterface{
    [self.view addSubview:self.tableView];
    self.tableView.sd_layout
    .topSpaceToView(self.navigView, 0)
    .bottomSpaceToView(self.view, 0)
    .leftSpaceToView(self.view, 0)
    .rightSpaceToView(self.view, 0);
    
}

#pragma mark - UITableViewDataSource,UITableViewDelegate
/**  返回组个数  */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
/**  返回cell个数  */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titleArray.count;
}
/**  返回cell高度  */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return ItemHeight * 100;
}
/**  cell初始化  */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YBMySettingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CELLID forIndexPath:indexPath];
    if (indexPath.row == 0) {
        cell.dataDic = @{@"title" : self.titleArray[indexPath.row] , @"content" : [NSString stringWithFormat:@"%@" , self.dataArray[indexPath.row]] , @"isHeadImage" : @"1"};
    }
    else{
        cell.dataDic = @{@"title" : self.titleArray[indexPath.row] , @"content" : [NSString stringWithFormat:@"%@" , self.dataArray[indexPath.row]] , @"isHeadImage" : @"0"};
    }
    
    return cell;
    
    
}



-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}


-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}


-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
}


/**  cell的点击事件  */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.titleArray[indexPath.row] isEqualToString:@"姓名"]) {
        MyInforChangeNameViewController *vc = [[MyInforChangeNameViewController alloc] init];
        vc.name = self.dataArray[indexPath.row];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([self.titleArray[indexPath.row] isEqualToString:@"手机号"]) {
        YBChangePhoneViewController *vc = [[YBChangePhoneViewController alloc] init];
        vc.phoneString = self.dataArray[indexPath.row];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

/**  初始化tableView  */
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 1, 1 ) style:UITableViewStyleGrouped];
        [_tableView adaptiveIOS11];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.separatorColor = [UIColor clearColor];
        _tableView.bounces = NO;
        [_tableView registerClass:[YBMySettingTableViewCell class] forCellReuseIdentifier:CELLID];
        
        
    }
    return _tableView;
}

@end
